package org.example;

import java.util.ArrayList;
import java.util.List;

public class UserDao {
    List<User> userList;
    public UserDao(){
        userList = new ArrayList<>();
    }
    public List<User> getAll(){
        return new ArrayList<>(userList);
    }
//新增
    public boolean add(User user){
        userList.add(user);
        return true;
    }
    //删除
    public boolean delete(User user){
        userList.remove(user);
        return true;
    }
    //修改
    public boolean update(User user){
        for (User item : userList){
            if (user.getId()==item.getId()){
                item.setName(user.getName());
            }
        }
        return true;
    }
}